package com.tilas;
 
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.PutObjectResult;

import java.io.*;
 
 
public class AliOSSUtil {
    // Endpoint外网访问域名，以上海为例。
   private static String endpoint = "oss-cn-beijing.aliyuncs.com";
    // accessKeyId 和 accessKeySecret 是先前创建用户生成的
    private static  String accessKeyId = "LTAI5tGEE5rwYrGQT17HJtE2";
    private static String accessKeySecret = "zg6SNrmNVfO3nW8Y7SyJWSMiDWRVgA";
    private static String bucketName="java-ai-zyg";
    public static void uploadFile(String fileName,String saveFileName) throws FileNotFoundException {
        // 创建OSSClient实例。
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
        // 上传文件流。
        InputStream inputStream = new FileInputStream(fileName);
        PutObjectResult putObjectResult = ossClient.putObject(bucketName, saveFileName, inputStream);
        System.out.println(putObjectResult);
        // 关闭OSSClient。
        ossClient.shutdown();
    }
    public static void main(String[] args) throws FileNotFoundException {
        uploadFile("D:\\1.jpg","cat.jpg");
    }



 
}